package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.album.service.VodService;
import com.atguigu.tingshu.common.login.Login;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumTrackListVo;
import com.atguigu.tingshu.vo.album.TrackInfoVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.atguigu.tingshu.vo.album.TrackStatVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;

	@Autowired
	private VodService vodService;

	@PostMapping("uploadTrack")
	public Result<Map<String, Object>> uploadTrack(MultipartFile file){
		Map<String, Object> map=this.vodService.uploadTrack(file);
		return Result.ok(map);
	}
	@Login
	@PostMapping("saveTrackInfo")
	public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo){
		this.trackInfoService.saveTrackInfo(trackInfoVo);
		return Result.ok();
	}
	@Login
	@PostMapping("findUserTrackPage/{page}/{limit}")
	public Result<Page<TrackListVo>> findUserTrackPage(@PathVariable Integer page,
										   @PathVariable Integer limit, TrackInfoQuery query){
		Page<TrackListVo> trackListVos=this.trackInfoService.findUserTrackPage(page,limit,query);
		return Result.ok(trackListVos);
	}

	@GetMapping("getTrackInfo/{trackId}")
	public Result<TrackInfo> getTrackInfo(@PathVariable Long trackId){
		TrackInfo trackInfo = this.trackInfoService.getById(trackId);
		return Result.ok(trackInfo);
	}

	@Login
	@PutMapping("updateTrackInfo/{trackId}")
	public Result updateTrackInfo(@PathVariable Long trackId, @RequestBody TrackInfoVo trackInfoVo){
		this.trackInfoService.updateTrackInfo(trackId, trackInfoVo);
		return Result.ok();
	}
	//api/album/trackInfo/removeTrackInfo/51943
	@Login
	@DeleteMapping("removeTrackInfo/{trackId}")
	public Result removeTrackInfo(@PathVariable Long trackId){
		this.trackInfoService.removeTrackInfo(trackId);
		return Result.ok();
	}

	///album/trackInfo/findAlbumTrackPage/1429/1/10

	@Login(required = false)
	@GetMapping("findAlbumTrackPage/{albumId}/{page}/{limit}")
	public Result<Page<AlbumTrackListVo>> findAlbumTrackPage(
			@PathVariable Long albumId, @PathVariable Integer page, @PathVariable Integer limit
	){
		Page<AlbumTrackListVo> albumTrackListVoPage = this.trackInfoService.findAlbumTrackPage(albumId, page, limit);
		return Result.ok(albumTrackListVoPage);
	}
	//trackInfo/getTrackStatVo/48236
	@GetMapping("getTrackStatVo/{trackId}")
	public Result<TrackStatVo> getTrackStatVo(@PathVariable Long trackId){
		TrackStatVo statVo=this.trackInfoService.getTrackStatVo(trackId);
		return Result.ok(statVo);
	}
}

